package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author milian
 * @Date 2021/8/19 0019 22:10
 */
public class title4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/db10?useSSL=false";
        String username="root";
        String password="root";
        Connection conn = DriverManager.getConnection(url, username, password);
        String sql = "update account set money=money-500 where name='张三'";
        String sql1 ="update account set money=money+500 where name='李四'";
        Statement stem = conn.createStatement();
        try {
            conn.setAutoCommit(false);
            int i = stem.executeUpdate(sql);
            int s = stem.executeUpdate(sql1);
            System.out.println(i);
            System.out.println(s);
            conn.commit();
        } catch (SQLException throwables) {
            conn.rollback();
            throwables.printStackTrace();
        }
        stem.close();
        conn.close();

    }
}
